home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 2.iso / dist / fw_gsl.idb / usr / freeware / info / gsl-ref.info-9.z / gsl-ref.info-9
Text File  |  2000-10-09  |  50KB  |  1,185 lines

  1. This is gsl-ref.info, produced by Makeinfo version 3.12h from
  2. gsl-ref.texi.
  3.  
  4. INFO-DIR-SECTION Scientific software
  5. START-INFO-DIR-ENTRY
  6. * gsl-ref: (gsl-ref).                   GNU Scientific Library - Reference
  7. END-INFO-DIR-ENTRY
  8.  
  9.    This file documents the GNU Scientific Library.
  10.  
  11.    Copyright (C) 1996, 1997, 1998, 1999 The GSL Project.
  12.  
  13.    Permission is granted to make and distribute verbatim copies of this
  14. manual provided the copyright notice and this permission notice are
  15. preserved on all copies.
  16.  
  17.    Permission is granted to copy and distribute modified versions of
  18. this manual under the conditions for verbatim copying, provided that
  19. the entire resulting derived work is distributed under the terms of a
  20. permission notice identical to this one.
  21.  
  22.    Permission is granted to copy and distribute translations of this
  23. manual into another language, under the above conditions for modified
  24. versions, except that this permission notice may be stated in a
  25. translation approved by the Foundation.
  26.  
  27. 
  28. File: gsl-ref.info,  Node: Sorting objects,  Next: Sorting vectors,  Up: Sorting
  29.  
  30. Sorting objects
  31. ===============
  32.  
  33.    The following function provides a simple alternative to the standard
  34. library function `qsort'.  It is intended for systems lacking `qsort',
  35. not as a replacement for it.  The function `qsort' should be used
  36. whenever possible, as it will be faster and can provide stable ordering
  37. of equal elements.  Documentation for `qsort' is available in the `GNU
  38. C Library Reference Manual'.
  39.  
  40.    The functions described in this section are defined in the header
  41. file `gsl_heapsort.h'.
  42.  
  43.  - Function: void gsl_heapsort (void * ARRAY, size_t COUNT, size_t
  44.           SIZE, gsl_comparison_fn_t COMPARE)
  45.      This function sorts the COUNT members of the array ARRAY, each of
  46.      size SIZE, into ascending order using the comparision function
  47.      COMPARE.  The type of the comparison function is defined by,
  48.  
  49.           int (*gsl_comparison_fn_t) (const void * a, const void * b)
  50.  
  51.      A comparison function should return a negative integer if the first
  52.      argument is less than the second argument, `0' if the two arguments
  53.      are equal and a positive integer if the first argument is greater
  54.      than the second argument.
  55.  
  56.      For example, the following function can be used to sort doubles
  57.      into ascending numerical order.
  58.  
  59.           int
  60.           compare_doubles (const double * a, const double * b)
  61.           {
  62.               return (int) (*a - *b);
  63.           }
  64.  
  65.      The appropriate function call to perform the sort is,
  66.  
  67.           gsl_heapsort (array, size, sizeof(double), compare_doubles);
  68.  
  69.      Note that unlike `qsort' the heapsort algorithm cannot be made into
  70.      a stable sort by pointer arithmetic.  The trick of comparing
  71.      pointers for equal elements in the comparison function does not
  72.      work for the heapsort algorithm.  The heapsort algorithm performs
  73.      an internal rearrangement of the data which destroys its initial
  74.      ordering.
  75.  
  76.  - Function: int gsl_heapsort_index (size_t * p, const void * ARRAY,
  77.           size_t COUNT, size_t SIZE, gsl_comparison_fn_t COMPARE)
  78.      This function indirectly sorts the COUNT members of the array
  79.      ARRAY, each of size SIZE, into ascending order using the
  80.      comparision function COMPARE.  The resulting permutation is stored
  81.      in P, an array of length N.  The elements of P give the index of
  82.      the array element which would have been stored in that position if
  83.      the array had been sorted in place.  The first element of P gives
  84.      the index of the least element in ARRAY, and the last element of P
  85.      gives the index of the greatest element in ARRAY.  The array
  86.      itself is not changed.
  87.  
  88. 
  89. File: gsl-ref.info,  Node: Sorting vectors,  Next: Computing the rank,  Prev: Sorting objects,  Up: Sorting
  90.  
  91. Sorting vectors
  92. ===============
  93.  
  94.    The following functions will sort the elements of an array or vector,
  95. either directly or indirectly.  They are defined for all real and
  96. integer types using the normal suffix rules.  For example, the `float'
  97. versions of the array functions are `gsl_sort_float' and
  98. `gsl_sort_float_index'.  The corresponding vector functions are
  99. `gsl_sort_vector_float' and `gsl_sort_vector_float_index'.  The
  100. prototypes are available in the header files `gsl_sort_float.h'
  101. `gsl_sort_vector_float.h'.  The complete set of prototypes can be
  102. included using the header files `gsl_sort.h' and `gsl_sort_vector.h'.
  103.  
  104.    There are no functions for sorting complex arrays or vectors, since
  105. the ordering of complex numbers is not uniquely defined.  To sort a
  106. complex vector by magnitude compute a real vector containing the the
  107. magnitudes of the complex elements, and sort this vector indirectly.
  108. The resulting index gives the appropriate ordering of the original
  109. complex vector.
  110.  
  111.  - Function: void gsl_sort_vector (gsl_vector * V)
  112.      This function sorts the elements of the vector V into ascending
  113.      numerical order.
  114.  
  115.  - Function: void gsl_sort (double * DATA, size_t STRIDE, size_t N)
  116.      This function sorts the N elements of the array DATA with stride
  117.      STRIDE into ascending numerical order.
  118.  
  119.  - Function: int gsl_sort_vector_index (gsl_permutation * P, const
  120.           gsl_vector * V)
  121.      This function indirectly sorts the elements of the vector V into
  122.      ascending order, storing the resulting permutation in P.  The
  123.      elements of P give the index of the vector element which would
  124.      have been stored in that position if the vector had been sorted in
  125.      place.  The first element of P gives the index of the least element
  126.      in V, and the last element of P gives the index of the greatest
  127.      element in V.  The vector V is not changed.
  128.  
  129.  - Function: int gsl_sort_index (size_t * P, const double * DATA,
  130.           size_t STRIDE, size_t N)
  131.      This function indirectly sorts the N elements of the array DATA
  132.      with stride STRIDE into ascending order, storing the resulting
  133.      permutation in P.  The array P must be allocated to a sufficient
  134.      length to store the N elements of the permutation.  The elements
  135.      of P give the index of the array element which would have been
  136.      stored in that position if the array had been sorted in place.
  137.      The array DATA is not changed.
  138.  
  139. 
  140. File: gsl-ref.info,  Node: Computing the rank,  Next: Sorting Examples,  Prev: Sorting vectors,  Up: Sorting
  141.  
  142. Computing the rank
  143. ==================
  144.  
  145.    The "rank" of an element is its order in the sorted data.  The rank
  146. is the inverse of the index permutation, P.  It can be computed using
  147. the following algorithm,
  148.  
  149.      for (i = 0; i < p->size; i++)
  150.      {
  151.          size_t pi = p->data[i];
  152.          rank->data[pi] = i;
  153.      }
  154.  
  155. This can be computed directly from the function
  156. `gsl_permutation_invert(rank,p)'.
  157.  
  158.    The following function will print the rank of each element of the
  159. vector V,
  160.  
  161.      void
  162.      print_rank (gsl_vector * v)
  163.      {
  164.        size_t i;
  165.        gsl_permutation * perm = gsl_permutation_alloc(v->size);
  166.        gsl_permutation * rank = gsl_permutation_alloc(v->size);
  167.      
  168.        gsl_sort_vector_index (perm, v);
  169.        gsl_permutation_invert (rank, perm);
  170.      
  171.        for (i = 0; i < v->size; i++)
  172.         {
  173.          double vi = gsl_vector_get(v, i);
  174.          printf("element = %d, value = % .5f, rank = %d\n",
  175.                  i, vi, rank->data[i]);
  176.         }
  177.      
  178.        gsl_permutation_free (perm);
  179.        gsl_permutation_free (rank);
  180.      }
  181.  
  182. 
  183. File: gsl-ref.info,  Node: Sorting Examples,  Next: Sorting References and Further Reading,  Prev: Computing the rank,  Up: Sorting
  184.  
  185. Examples
  186. ========
  187.  
  188.    The following example shows how to use the permutation P to print
  189. the elements of the vector V in ascending order,
  190.  
  191.      gsl_sort_vector_index (p, v);
  192.      
  193.      for (i = 0; i < v->size; i++)
  194.      {
  195.          double vpi = gsl_vector_get(v, p->data[i]);
  196.          printf("order = %d, value = %g\n", i, vpi);
  197.      }
  198.  
  199. 
  200. File: gsl-ref.info,  Node: Sorting References and Further Reading,  Prev: Sorting Examples,  Up: Sorting
  201.  
  202. References and Further Reading
  203. ==============================
  204.  
  205. The subject of sorting is covered extensively in Knuth's `Sorting and
  206. Searching',
  207.  
  208.      Donald E. Knuth, `The Art of Computer Programming: Sorting and
  209.      Searching' (Vol 3, 3rd Ed, 1997), Addison-Wesley, ISBN 0201896850.
  210.  
  211. The Heapsort algorithm is described in the following book,
  212.  
  213.      Robert Sedgewick, `Algorithms in C', Addison-Wesley, ISBN
  214.      0201514257.
  215.  
  216. 
  217. File: gsl-ref.info,  Node: Statistics,  Next: Histograms,  Prev: Sorting,  Up: Top
  218.  
  219. Statistics
  220. **********
  221.  
  222.    This chapter describes the statistical functions in the library.  The
  223. basic statistical functions include routines to compute the mean,
  224. variance and standard deviation.  More advanced functions allow you to
  225. calculate absolute deviations, skewness, and kurtosis as well as the
  226. median and arbitrary percentiles.  Statistical tests for comparing
  227. different datasets, such as the t-test, are also included.
  228.  
  229.    The functions are available in versions for datasets in the standard
  230. floating-point and integer types.  The versions for double precision
  231. floating-point data have the prefix `gsl_stats' and the versions for
  232. integer data have the prefix `gsl_stats_int'.
  233.  
  234.    The algorithms use recurrence relations to compute average
  235. quantities in a stable way, without large intermediate values that
  236. might overflow.
  237.  
  238. * Menu:
  239.  
  240. * Mean and standard deviation and variance::
  241. * Absolute deviation::
  242. * Higher moments (skewness and kurtosis)::
  243. * Autocorrelation::
  244. * Covariance::
  245. * Weighted Samples::
  246. * Maximum and Minimum values::
  247. * Median and Percentiles::
  248. * Statistical tests::
  249. * Example statistical programs::
  250. * Statistics References and Further Reading::
  251.  
  252. 
  253. File: gsl-ref.info,  Node: Mean and standard deviation and variance,  Next: Absolute deviation,  Up: Statistics
  254.  
  255. Mean, Standard Deviation and Variance
  256. =====================================
  257.  
  258.  - Statistics: double gsl_stats_mean (const double DATA[], size_t
  259.           STRIDE, size_t N)
  260.      This function returns the arithmetic mean of DATA, a dataset of
  261.      length N with stride STRIDE.  The arithmetic mean, or "sample
  262.      mean", is denoted by \Hat\mu and defined as,
  263.  
  264.           \Hat\mu = (1/N) \sum x_i
  265.  
  266.      where x_i are the elements of the dataset DATA.  For samples drawn
  267.      from a gaussian distribution the variance of \Hat\mu is \sigma^2 /
  268.      N.
  269.  
  270.  - Statistics: double gsl_stats_variance (const double DATA[], size_t
  271.           STRIDE, size_t N)
  272.      This function returns the estimated, or "sample", variance of
  273.      DATA, a dataset of length N with stride STRIDE.  The estimated
  274.      variance is denoted by \Hat\sigma^2 and is defined by,
  275.  
  276.           \Hat\sigma^2 = (1/(N-1)) \sum (x_i - \Hat\mu)^2
  277.  
  278.      where x_i are the elements of the dataset DATA.  Note that the
  279.      normalization factor of 1/(N-1) results from the derivation of
  280.      \Hat\sigma^2 as an unbiased estimator of the population variance
  281.      \sigma^2.  For samples drawn from a gaussian distribution the
  282.      variance of \Hat\sigma^2 itself is 2 \sigma^4 / N.
  283.  
  284.      This function computes the mean via a call to `gsl_stats_mean'.  If
  285.      you have already computed the mean then you can pass it directly to
  286.      `gsl_stats_variance_m'.
  287.  
  288.  - Statistics: double gsl_stats_variance_m (const double DATA[], size_t
  289.           STRIDE, size_t N, double MEAN)
  290.      This function returns the sample variance of DATA relative to the
  291.      given value of MEAN.  The function is computed with \Hat\mu
  292.      replaced by the value of MEAN that you supply,
  293.  
  294.           \Hat\sigma^2 = (1/(N-1)) \sum (x_i - mean)^2
  295.  
  296.  - Statistics: double gsl_stats_sd (const double DATA[], size_t STRIDE,
  297.           size_t N)
  298.  - Statistics: double gsl_stats_sd_m (const double DATA[], size_t
  299.           STRIDE, size_t N, double MEAN)
  300.      The standard deviation is defined as the square root of the
  301.      variance.  These functions return the square root of the
  302.      corresponding variance functions above.
  303.  
  304.  - Statistics: double gsl_stats_variance_with_fixed_mean (const double
  305.           DATA[], size_t STRIDE, size_t N, double MEAN)
  306.      This function computes an unbiased estimate of the variance of
  307.      DATA when the population mean MEAN of the underlying distribution
  308.      is known _a priori_.  In this case the estimator for the variance
  309.      uses the factor 1/N and the sample mean \Hat\mu is replaced by the
  310.      known population mean \mu,
  311.  
  312.           \Hat\sigma^2 = (1/N) \sum (x_i - \mu)^2
  313.  
  314.  
  315.  - Statistics: double gsl_stats_sd_with_fixed_mean (const double
  316.           DATA[], size_t STRIDE, size_t N, double MEAN)
  317.      This function calculates the standard deviation of DATA for a a
  318.      fixed population mean MEAN.  The result is the square root of the
  319.      corresponding variance function.
  320.  
  321. 
  322. File: gsl-ref.info,  Node: Absolute deviation,  Next: Higher moments (skewness and kurtosis),  Prev: Mean and standard deviation and variance,  Up: Statistics
  323.  
  324. Absolute deviation
  325. ==================
  326.  
  327.  - Statistics: double gsl_stats_absdev (const double DATA[], size_t
  328.           STRIDE, size_t N)
  329.      This function computes the absolute deviation from the mean of
  330.      DATA, a dataset of length N with stride STRIDE.  The absolute
  331.      deviation from the mean is defined as,
  332.  
  333.           absdev  = (1/N) \sum |x_i - \Hat\mu|
  334.  
  335.      where x_i are the elements of the dataset DATA.  The absolute
  336.      deviation from the mean provides a more robust measure of the
  337.      width of a distribution than the variance.  This function computes
  338.      the mean of DATA via a call to `gsl_stats_mean'.
  339.  
  340.  - Statistics: double gsl_stats_absdev_m (const double DATA[], size_t
  341.           STRIDE, size_t N, double MEAN)
  342.      This function computes the absolute deviation of the dataset DATA
  343.      relative to the given value of MEAN,
  344.  
  345.           absdev  = (1/N) \sum |x_i - mean|
  346.  
  347.      This function is useful if you have already computed the mean of
  348.      DATA (and want to avoid recomputing it), or wish to calculate the
  349.      absolute deviation relative to another value (such as zero, or the
  350.      median).
  351.  
  352. 
  353. File: gsl-ref.info,  Node: Higher moments (skewness and kurtosis),  Next: Autocorrelation,  Prev: Absolute deviation,  Up: Statistics
  354.  
  355. Higher moments (skewness and kurtosis)
  356. ======================================
  357.  
  358.  - Statistics: double gsl_stats_skew (const double DATA[], size_t
  359.           STRIDE, size_t N)
  360.      This function computes the skewness of DATA, a dataset of length N
  361.      with stride STRIDE.  The skewness is defined as,
  362.  
  363.           skew = (1/N) \sum ((x_i - \Hat\mu)/\Hat\sigma)^3
  364.  
  365.      where x_i are the elements of the dataset DATA.  The skewness
  366.      measures the asymmetry of the tails of a distribution.
  367.  
  368.      The function computes the mean and estimated standard deviation of
  369.      DATA via calls to `gsl_stats_mean' and `gsl_stats_sd'.
  370.  
  371.  - Statistics: double gsl_stats_skew_m_sd (const double DATA[], size_t
  372.           STRIDE, size_t N, double MEAN, double SD)
  373.      This function computes the skewness of the dataset DATA using the
  374.      given values of the mean MEAN and standard deviation SD,
  375.  
  376.           skew = (1/N) \sum ((x_i - mean)/sd)^3
  377.  
  378.      These functions are useful if you have already computed the mean
  379.      and standard deviation of DATA and want to avoid recomputing them.
  380.  
  381.  - Statistics: double gsl_stats_kurtosis (const double DATA[], size_t
  382.           STRIDE, size_t N)
  383.      This function computes the kurtosis of DATA, a dataset of length N
  384.      with stride STRIDE.  The kurtosis is defined as,
  385.  
  386.           kurtosis = ((1/N) \sum ((x_i - \Hat\mu)/\Hat\sigma)^4)  - 3
  387.  
  388.      The kurtosis measures how sharply peaked a distribution is,
  389.      relative to its width.  The kurtosis is normalized to zero for a
  390.      gaussian distribution.
  391.  
  392.  - Statistics: double gsl_stats_kurtosis_m_sd (const double DATA[],
  393.           size_t STRIDE, size_t N, double MEAN, double SD)
  394.      This function computes the kurtosis of the dataset DATA using the
  395.      given values of the mean MEAN and standard deviation SD,
  396.  
  397.           kurtosis = ((1/N) \sum ((x_i - mean)/sd)^4) - 3
  398.  
  399.      This function is useful if you have already computed the mean and
  400.      standard deviation of DATA and want to avoid recomputing them.
  401.  
  402. 
  403. File: gsl-ref.info,  Node: Autocorrelation,  Next: Covariance,  Prev: Higher moments (skewness and kurtosis),  Up: Statistics
  404.  
  405. Autocorrelation
  406. ===============
  407.  
  408.  - Function: double gsl_stats_lag1_autocorrelation (const double
  409.           data[], const size_t STRIDE, const size_t N)
  410.      This function computes the lag-1 autocorrelation of the dataset
  411.      DATA.
  412.  
  413.           a_1 = {\sum_{i = 1}^{n} (x_{i} - \Hat\mu) (x_{i-1} - \Hat\mu)
  414.                  \over
  415.                  \sum_{i = 1}^{n} (x_{i} - \Hat\mu) (x_{i} - \Hat\mu)}
  416.  
  417.  
  418.  - Function: double gsl_stats_lag1_autocorrelation_m (const double
  419.           data[], const size_t STRIDE, const size_t N, const double
  420.           MEAN)
  421.  
  422. 
  423. File: gsl-ref.info,  Node: Covariance,  Next: Weighted Samples,  Prev: Autocorrelation,  Up: Statistics
  424.  
  425. Covariance
  426. ==========
  427.  
  428.  - Function: double gsl_stats_covariance (const double DATA1[], const
  429.           size_t STRIDE1, const double data2[], const size_t STRIDE2,
  430.           const size_t N)
  431.      This function computes the covariance of the datasets DATA1 and
  432.      DATA2 which must both be of the same length N.
  433.  
  434.           covar = (1/(n - 1)) \sum_{i = 1}^{n} (x_i - \Hat x) (y_i - \Hat y)
  435.  
  436.  
  437.  - Function: double gsl_stats_covariance_m (const double DATA1[], const
  438.           size_t STRIDE1, const double DATA2[], const size_t N, const
  439.           double MEAN1, const double MEAN2)
  440.  
  441. 
  442. File: gsl-ref.info,  Node: Weighted Samples,  Next: Maximum and Minimum values,  Prev: Covariance,  Up: Statistics
  443.  
  444. Weighted Samples
  445. ================
  446.  
  447.    The functions described in this section allow the computation of
  448. statistics for weighted samples.  The functions accept an array of
  449. samples, x_i, with associated weights, w_i.  Each sample x_i is
  450. considered as having been drawn from a Gaussian distribution with
  451. variance \sigma_i^2.  The sample weight w_i is defined as the
  452. reciprocal of this variance, w_i = 1/\sigma_i^2.  Setting a weight to
  453. zero corresponds to removing a sample from a dataset.
  454.  
  455.  - Statistics: double gsl_stats_wmean (const double W[], size_t
  456.           WSTRIDE, const double DATA[], size_t STRIDE, size_t N)
  457.      This function returns the weighted mean of the dataset DATA with
  458.      stride STRIDE and length N, using the set of weights W with stride
  459.      WSTRIDE and length N.  The weighted mean is defined as,
  460.  
  461.           \Hat\mu = (\sum w_i x_i) / (\sum w_i)
  462.  
  463.  - Statistics: double gsl_stats_wvariance (const double W[], size_t
  464.           WSTRIDE, const double DATA[], size_t STRIDE, size_t N)
  465.      This function returns the estimated variance of the dataset DATA
  466.      with stride STRIDE and length N, using the set of weights W with
  467.      stride WSTRIDE and length N.  The estimated variance of a weighted
  468.      dataset is defined as,
  469.  
  470.           \Hat\sigma^2 = ((\sum w_i)/((\sum w_i)^2 - \sum (w_i^2)))
  471.                           \sum w_i (x_i - \Hat\mu)^2
  472.  
  473.      Note that this expression reduces to an unweighted variance with
  474.      the familiar 1/(N-1) factor when there are N equal non-zero
  475.      weights.
  476.  
  477.  - Statistics: double gsl_stats_wvariance_m (const double W[], size_t
  478.           WSTRIDE, const double DATA[], size_t STRIDE, size_t N, double
  479.           WMEAN)
  480.  
  481.  - Statistics: double gsl_stats_wsd (const double W[], size_t WSTRIDE,
  482.           const double DATA[], size_t STRIDE, size_t N)
  483.      The standard deviation is defined as the square root of the
  484.      variance.  This function returns the square root of the
  485.      corresponding variance function above.
  486.  
  487.  - Statistics: double gsl_stats_wsd_m (const double W[], size_t
  488.           WSTRIDE, const double DATA[], size_t STRIDE, size_t N, double
  489.           WMEAN)
  490.  
  491.  - Statistics: double gsl_stats_wvariance_with_fixed_mean (const double
  492.           W[], size_t WSTRIDE, const double DATA[], size_t STRIDE,
  493.           size_t N)
  494.      This function computes an unbiased estimate of the variance of
  495.      weighted dataset DATA when the population mean MEAN of the
  496.      underlying distribution is known _a priori_.  In this case the
  497.      estimator for the variance replaces the sample mean \Hat\mu by the
  498.      known population mean \mu,
  499.  
  500.           \Hat\sigma^2 = (\sum w_i (x_i - \mu)^2) / (\sum w_i)
  501.  
  502.  - Statistics: double gsl_stats_wsd_with_fixed_mean (const double W[],
  503.           size_t WSTRIDE, const double DATA[], size_t STRIDE, size_t N)
  504.      The standard deviation is defined as the square root of the
  505.      variance.  This function returns the square root of the
  506.      corresponding variance function above.
  507.  
  508.  - Statistics: double gsl_stats_wabsdev (const double W[], size_t
  509.           WSTRIDE, const double DATA[], size_t STRIDE, size_t N)
  510.      This function computes the absolute deviation from the mean of
  511.      DATA.  The absolute deviation from the mean is defined as,
  512.  
  513.           absdev = (\sum w_i |x_i - \Hat\mu|) / (\sum w_i)
  514.  
  515.  - Statistics: double gsl_stats_wabsdev_m (const double W[], size_t
  516.           WSTRIDE, const double DATA[], size_t STRIDE, size_t N, double
  517.           WMEAN)
  518.  
  519.  - Statistics: double gsl_stats_wskew (const double W[], size_t
  520.           WSTRIDE, const double DATA[], size_t STRIDE, size_t N)
  521.           skew = (\sum w_i ((x_i - xbar)/\sigma)^3) / (\sum w_i)
  522.  
  523.  - Statistics: double gsl_stats_wskew_m_sd (const double W[], size_t
  524.           WSTRIDE, const double DATA[], size_t STRIDE, size_t N, double
  525.           WMEAN, double WSD)
  526.  
  527.  - Statistics: double gsl_stats_wkurtosis (const double W[], size_t
  528.           WSTRIDE, const double DATA[], size_t STRIDE, size_t N)
  529.           kurtosis = ((\sum w_i ((x_i - xbar)/sigma)^4) / (\sum w_i)) - 3
  530.  
  531.  - Statistics: double gsl_stats_wkurtosis_m_sd (const double W[],
  532.           size_t WSTRIDE, const double DATA[], size_t STRIDE, size_t N,
  533.           double WMEAN, double WSD)
  534.  
  535. 
  536. File: gsl-ref.info,  Node: Maximum and Minimum values,  Next: Median and Percentiles,  Prev: Weighted Samples,  Up: Statistics
  537.  
  538. Maximum and Minimum values
  539. ==========================
  540.  
  541.  - Statistics: double gsl_stats_max (const double DATA[], size_t
  542.           STRIDE, size_t N)
  543.      This function returns the maximum value in DATA, a dataset of
  544.      length N with stride STRIDE.  The maximum value is defined as the
  545.      value of the element x_i which satisfies x_i >= x_j for all j.
  546.  
  547.      If you want instead to find the element with the largest absolute
  548.      magnitude you will need to apply `fabs' or `abs' to your data
  549.      before calling this function.
  550.  
  551.  - Statistics: double gsl_stats_min (const double DATA[], size_t
  552.           STRIDE, size_t N)
  553.      This function returns the minimum value in DATA, a dataset of
  554.      length N with stride STRIDE.  The minimum value is defined as the
  555.      value of the element x_i which satisfies x_i <= x_j for all j.
  556.  
  557.      If you want instead to find the element with the smallest absolute
  558.      magnitude you will need to apply `fabs' or `abs' to your data
  559.      before calling this function.
  560.  
  561.  - Statistics: void gsl_stats_minmax (double * MIN, double * MAX, const
  562.           double DATA[], size_t STRIDE, size_t N)
  563.      This function finds both the minimum and maximum values MIN, MAX
  564.      in DATA in a single pass.
  565.  
  566.  - Statistics: size_t gsl_stats_max_index (const double DATA[], size_t
  567.           STRIDE, size_t N)
  568.      This function returns the index of the maximum value in DATA, a
  569.      dataset of length N with stride STRIDE.  The maximum value is
  570.      defined as the value of the element x_i which satisfies x_i >= x_j
  571.      for all j.  When there are several equal maximum elements then the
  572.      first one is chosen.
  573.  
  574.  - Statistics: size_t gsl_stats_min_index (const double DATA[], size_t
  575.           STRIDE, size_t N)
  576.      This function returns the index of the minimum value in DATA, a
  577.      dataset of length N with stride STRIDE.  The minimum value is
  578.      defined as the value of the element x_i which satisfies x_i >= x_j
  579.      for all j.  When there are several equal minimum elements then the
  580.      first one is chosen.
  581.  
  582.  - Statistics: void gsl_stats_minmax_index (size_t * MIN_INDEX, size_t
  583.           * MAX_INDEX, const double DATA[], size_t STRIDE, size_t N)
  584.      This function returns the indexes MIN_INDEX, MAX_INDEX of the
  585.      minimum and maximum values in DATA in a single pass.
  586.  
  587. 
  588. File: gsl-ref.info,  Node: Median and Percentiles,  Next: Statistical tests,  Prev: Maximum and Minimum values,  Up: Statistics
  589.  
  590. Median and Percentiles
  591. ======================
  592.  
  593.    The median and percentile functions described in this section
  594. operate on sorted data.  For convenience we use "quantiles", measured
  595. on a scale of 0 to 1, instead of percentiles (which use a scale of 0 to
  596. 100).
  597.  
  598.  - Statistics: double gsl_stats_median_from_sorted_data (const double
  599.           SORTED_DATA[], size_t STRIDE, size_t N)
  600.      This function returns the median value of SORTED_DATA, a dataset
  601.      of length N with stride STRIDE.  The elements of the array must be
  602.      in ascending numerical order.  There are no checks to see whether
  603.      the data are sorted, so the function `gsl_sort' should always be
  604.      used first.
  605.  
  606.      When the dataset has an odd number of elements the median is the
  607.      value of element (n-1)/2.  When the dataset has an even number of
  608.      elements the median is the mean of the two nearest middle values,
  609.      elements (n-1)/2 and n/2.  Since the algorithm for computing the
  610.      median involves interpolation this function always returns a
  611.      floating-point number, even for integer data types.
  612.  
  613.  - Statistics: double gsl_stats_quantile_from_sorted_data (const double
  614.           SORTED_DATA[], size_t STRIDE, size_t N, double F)
  615.      This function returns a quantile value of SORTED_DATA, a
  616.      double-precision array of length N with stride STRIDE.  The
  617.      elements of the array must be in ascending numerical order.  The
  618.      quantile is determined by the F, a fraction between 0 and 1.  For
  619.      example, to compute the value of the 75th percentile F should have
  620.      the value 0.75.
  621.  
  622.      There are no checks to see whether the data are sorted, so the
  623.      function `gsl_sort' should always be used first.
  624.  
  625.      The quantile is found by interpolation, using the formula
  626.  
  627.           quantile = (1 - \delta) x_i + \delta x_{i+1}
  628.  
  629.      where i is `floor'((n - 1)f) and \delta is (n-1)f - i.
  630.  
  631.      Thus the minimum value of the array (`data[0*stride]') is given by
  632.      F equal to zero, the maximum value (`data[(n-1)*stride]') is given
  633.      by F equal to one and the median value is given by F equal to 0.5.
  634.      Since the algorithm for computing quantiles involves
  635.      interpolation this function always returns a floating-point
  636.      number, even for integer data types.
  637.  
  638. 
  639. File: gsl-ref.info,  Node: Statistical tests,  Next: Example statistical programs,  Prev: Median and Percentiles,  Up: Statistics
  640.  
  641. Statistical tests
  642. =================
  643.  
  644.    FIXME, do more work on the statistical tests
  645.  
  646. 
  647. File: gsl-ref.info,  Node: Example statistical programs,  Next: Statistics References and Further Reading,  Prev: Statistical tests,  Up: Statistics
  648.  
  649. Example statistical programs
  650. ============================
  651.  
  652.    Here is a basic example of how to use the statistical functions:
  653.  
  654.      #include <stdio.h>
  655.      #include <gsl/gsl_statistics.h>
  656.      
  657.      int main()
  658.      {
  659.        double data[5] = {17.2, 18.1, 16.5, 18.3, 12.6} ;
  660.        double mean, variance, largest, smallest;
  661.      
  662.        mean     = gsl_stats_mean(data, 1, 5);
  663.        variance = gsl_stats_variance(data, 1, 5);
  664.        largest  = gsl_stats_max(data, 1, 5);
  665.        smallest = gsl_stats_min(data, 1, 5);
  666.      
  667.        printf("The dataset is %g, %g, %g, %g, %g\n",
  668.              data[0], data[1], data[2], data[3], data[4]);
  669.      
  670.        printf("The sample mean is %g\n", mean) ;
  671.        printf("The estimated variance is %g\n", variance) ;
  672.        printf("The largest value is %g\n", largest) ;
  673.        printf("The smallest value is %g\n", smallest) ;
  674.      }
  675.  
  676.    The program should produce the following output,
  677.  
  678.      The dataset is 17.2, 18.1, 16.5, 18.3, 12.6
  679.      The sample mean is 16.54
  680.      The estimated variance is 4.2984
  681.      The largest value is 18.3
  682.      The smallest value is 12.6
  683.  
  684.    Here is an example using sorted data,
  685.  
  686.      #include <stdio.h>
  687.      #include <gsl/gsl_sort.h>
  688.      #include <gsl/gsl_statistics.h>
  689.      
  690.      int main()
  691.      {
  692.        double data[5] = {17.2, 18.1, 16.5, 18.3, 12.6} ;
  693.        double median, upperq, lowerq;
  694.      
  695.        printf("The original dataset is %g, %g, %g, %g, %g\n",
  696.              data[0], data[1], data[2], data[3], data[4]);
  697.      
  698.        gsl_sort (data, 1, 5) ;
  699.      
  700.        printf("The sorted dataset is %g, %g, %g, %g, %g\n",
  701.              data[0], data[1], data[2], data[3], data[4]);
  702.      
  703.        median   = gsl_stats_median_from_sorted_data(data, 1, 5);
  704.        upperq   = gsl_stats_quantile_from_sorted_data(data, 1, 5, 0.75);
  705.        lowerq   = gsl_stats_quantile_from_sorted_data(data, 1, 5, 0.25);
  706.      
  707.        printf("The median is %g\n", median) ;
  708.        printf("The upper quartile is %g\n", upperq) ;
  709.        printf("The lower quartile is %g\n", lowerq) ;
  710.      }
  711.  
  712.    This program should produce the following output,
  713.  
  714.      The original dataset is 17.2, 18.1, 16.5, 18.3, 12.6
  715.      The sorted dataset is 12.6, 16.5, 17.2, 18.1, 18.3
  716.      The median is 17.2
  717.      The upper quartile is 18.1
  718.      The lower quartile is 16.5
  719.  
  720. 
  721. File: gsl-ref.info,  Node: Statistics References and Further Reading,  Prev: Example statistical programs,  Up: Statistics
  722.  
  723. References and Further Reading
  724. ==============================
  725.  
  726. The standard reference for almost any topic in statistics is the
  727. multi-volume `Advanced Theory of Statistics' by Kendall and Stuart.
  728.  
  729.      Maurice Kendall, Alan Stuart, and J. Keith Ord.  `The Advanced
  730.      Theory of Statistics' (multiple volumes) reprinted as `Kendall's
  731.      Advanced Theory of Statistics'.  Wiley, ISBN 047023380X.
  732.  
  733. Many statistical concepts can be more easily understood by a Bayesian
  734. approach.  The following book by Gelman, Carlin, Stern and Rubin gives a
  735. comprehensive coverage of the subject.
  736.  
  737.      Andrew Gelman, John B. Carlin, Hal S. Stern, Donald B. Rubin.
  738.      `Bayesian Data Analysis'.  Chapman & Hall, ISBN 0412039915.
  739.  
  740. For physicists the Particle Data Group provides useful reviews of
  741. Probability and Statistics in the "Mathematical Tools" section of its
  742. Annual Review of Particle Physics.
  743.  
  744.      `Review of Particle Properties' R.M. Barnett et al., Physical
  745.      Review D54, 1 (1996)
  746.  
  747. The Review of Particle Physics is available online at
  748. <http://pdg.lbl.gov/>.
  749.  
  750. 
  751. File: gsl-ref.info,  Node: Histograms,  Next: One dimensional Root-Finding,  Prev: Statistics,  Up: Top
  752.  
  753. Histograms
  754. **********
  755.  
  756.    This chapter describes functions for creating histograms.  Histograms
  757. provide a convenient way of summarizing the distribution of a set of
  758. data. A histogram consists of a set of "bins" which count the number of
  759. events falling into a given range of a continuous variable x.  In GSL
  760. the bins of a histogram contain floating-point numbers, so they can be
  761. used to record both integer and non-integer distributions.  The bins
  762. can use arbitrary sets of ranges (uniformly spaced bins are the
  763. default).  Both one and two-dimensional histograms are supported.
  764.  
  765.    Once a histogram has been created it can also be converted into a
  766. probability distribution function.  The library provides efficient
  767. routines for selecting random samples from probability distributions.
  768. This can be useful for generating simulations based real data.
  769.  
  770. * Menu:
  771.  
  772. * The histogram struct::
  773. * Histogram allocation::
  774. * Copying Histograms::
  775. * Updating and accessing histogram elements::
  776. * Searching histogram ranges::
  777. * Histogram Statistics::
  778. * Histogram Operations::
  779. * Reading and writing histograms::
  780. * Resampling from histograms::
  781. * The histogram probability distribution struct::
  782. * Example programs for histograms::
  783. * Two dimensional histograms::
  784. * The 2D histogram struct::
  785. * 2D Histogram allocation::
  786. * Copying 2D Histograms::
  787. * Updating and accessing 2D histogram elements::
  788. * Searching 2D histogram ranges::
  789. * 2D Histogram Statistics::
  790. * 2D Histogram Operations::
  791. * Reading and writing 2D histograms::
  792. * Resampling from 2D histograms::
  793. * Example programs for 2D histograms::
  794.  
  795. 
  796. File: gsl-ref.info,  Node: The histogram struct,  Next: Histogram allocation,  Up: Histograms
  797.  
  798. The histogram struct
  799. ====================
  800.  
  801.    A histogram is defined by the following struct,
  802.  
  803.  - Data Type: gsl_histogram
  804.     `size_t n'
  805.           This is the number of histogram bins
  806.  
  807.     `double * range'
  808.           The ranges of the bins are stored in an array of N+1 elements
  809.           pointed to by RANGE.
  810.  
  811.     `double * bin'
  812.           The counts for each bin are stored in an array of N elements
  813.           pointed to by BIN.  The bins are floating-point numbers, so
  814.           you can increment them by non-integer values if necessary.
  815.  
  816. The range for BIN[i] is given by RANGE[i] to RANGE[i+1].  For n bins
  817. there are n+1 entries in the array RANGE.  Each bin is inclusive at the
  818. lower end and exclusive at the upper end.  Mathematically this means
  819. that the bins are defined by the following inequality,
  820.  
  821.      bin[i] corresponds to range[i] <= x < range[i+1]
  822.  
  823. Here is a diagram of the correspondence between ranges and bins on the
  824. number-line for x,
  825.  
  826.  
  827.         r[0]      r[1]      r[2]      r[3]      r[4]      r[5]
  828.        ---|---------|---------|---------|---------|---------|---  x
  829.           [ bin[0] )[ bin[1] )[ bin[2] )[ bin[3] )[ bin[5] )
  830.  
  831. In this picture the values of the RANGE array are denoted by r.  On the
  832. left-hand side of each bin the square bracket "`['" denotes an
  833. inclusive lower bound (r <= x), and the round parentheses "`)'" on the
  834. right-hand side denote an exclusive upper bound (x < r).  Thus any
  835. samples which fall on the upper end of the histogram are excluded.  If
  836. you want to include this value for the last bin you will need to add an
  837. extra bin to your histogram.
  838.  
  839.    The `gsl_histogram' struct and its associated functions are defined
  840. in the header file `gsl_histogram.h'.
  841.  
  842. 
  843. File: gsl-ref.info,  Node: Histogram allocation,  Next: Copying Histograms,  Prev: The histogram struct,  Up: Histograms
  844.  
  845. Histogram allocation
  846. ====================
  847.  
  848.    The functions for allocating memory to a histogram follow the style
  849. of `malloc' and `free'.  In addition they also perform their own error
  850. checking.  If there is insufficient memory available to allocate a
  851. histogram then the functions call the GSL error handler (with an error
  852. number of `GSL_ENOMEM') in addition to returning a null pointer.  Thus
  853. if you use the library error handler to abort your program then it
  854. isn't necessary to check every histogram `alloc'.
  855.  
  856.  - Function: gsl_histogram * gsl_histogram_calloc (size_t N)
  857.      This function allocates memory for a histogram with N bins, and
  858.      returns a pointer to its newly initialized `gsl_histogram' struct.
  859.      The bins are uniformly spaced with a total range of 0 <=  x < n,
  860.      as shown in the table below.
  861.  
  862.           bin[0] corresponds to 0 \le  x < 1
  863.           bin[1] corresponds to 1 \le  x < 2
  864.           ......
  865.           bin[n-1] corresponds to n-1 \le  x < n
  866.  
  867.      The bins are initialized to zero so the histogram is ready for use.
  868.  
  869.      If insufficient memory is available a null pointer is returned and
  870.      the error handler is invoked with an error code of `GSL_ENOMEM'.
  871.  
  872.  - Function: gsl_histogram * gsl_histogram_calloc_uniform (size_t N,
  873.           double XMIN, double XMAX)
  874.      This function allocates memory for a histogram with N uniformly
  875.      spaced bins from XMIN to XMAX, and returns a pointer to the newly
  876.      initialized `gsl_histogram' struct.  The bins are shown in the
  877.      table below,
  878.  
  879.           bin[0] corresponds to xmin \le  x < xmin + d
  880.           bin[1] corresponds to xmin + d \le  x < xmin + 2 d
  881.           ......
  882.           bin[n-1] corresponds to xmin + (n-1)d \le  x < xmax
  883.  
  884.      where d is the bin spacing, (xmax-xmin)/n.  Each bin is
  885.      initialized to zero.
  886.  
  887.      If insufficient memory is available a null pointer is returned and
  888.      the error handler is invoked with an error code of `GSL_ENOMEM'.
  889.  
  890.    To create a histogram with non-uniform bins you will need to call
  891. `gsl_histogram_calloc' to prepare a new histogram struct and then
  892. modify the `range' array to use your desired bin limits.  The ranges
  893. can be arbitrary, subject to the restriction that they are monotonically
  894. increasing.
  895.  
  896.    For example, the following code fragment shows how to create a
  897. histogram with logarithmic bins from 1--10, 10--100 and 100--1000.
  898.  
  899.      gsl_histogram * h = gsl_histogram_calloc (3) ;
  900.      
  901.      h->range[0] = 1.0 ;     /* bin[0] covers the range 1 <= x < 10 */
  902.      h->range[1] = 10.0 ;    /* bin[1] covers the range 10 <= x < 100 */
  903.      h->range[2] = 100.0 ;   /* bin[2] covers the range 100 <= x < 1000 */
  904.      h->range[3] = 1000.0 ;
  905.  
  906. Note that the size of the RANGE array is automatically defined as
  907. `double range[4]' by `gsl_histogram_calloc', and is one element bigger
  908. than the array of bins `double bin[3]'.  Thus the range array safely
  909. includes extra space for the final upper value, RANGE[3].
  910.  
  911.  - Function: gsl_histogram * gsl_histogram_calloc_range (size_t N,
  912.           double * RANGE)
  913.      This function allocates a histogram of size N using the n+1 bin
  914.      ranges specified by the array RANGE.
  915.  
  916.  - Function: void gsl_histogram_free (gsl_histogram * h)
  917.      This function frees the histogram H and all of the memory
  918.      associated with it.
  919.  
  920. 
  921. File: gsl-ref.info,  Node: Copying Histograms,  Next: Updating and accessing histogram elements,  Prev: Histogram allocation,  Up: Histograms
  922.  
  923. Copying Histograms
  924. ==================
  925.  
  926.  - Function: int gsl_histogram_memcpy (gsl_histogram * DEST, const
  927.           gsl_histogram * SRC)
  928.      This function copies the histogram SRC into the pre-existing
  929.      histogram DEST, making DEST into an exact copy of SRC.  The two
  930.      histograms must be of the same size.
  931.  
  932.  - Function: gsl_histogram * gsl_histogram_clone (const gsl_histogram *
  933.           SRC)
  934.      This function returns a pointer to a newly created histogram which
  935.      is an exact copy of the histogram SRC.
  936.  
  937. 
  938. File: gsl-ref.info,  Node: Updating and accessing histogram elements,  Next: Searching histogram ranges,  Prev: Copying Histograms,  Up: Histograms
  939.  
  940. Updating and accessing histogram elements
  941. =========================================
  942.  
  943.    There are two ways to access histogram bins, either by specifying an
  944. x coordinate or by using the bin-index directly.  The functions for
  945. accessing the histogram through x coordinates use a binary search to
  946. identify the bin which covers the appropriate range.
  947.  
  948.  - Function: int gsl_histogram_increment (gsl_histogram * h, double x)
  949.      This function updates the histogram H by adding one (1.0) to the
  950.      bin whose range contains the coordinate X.
  951.  
  952.      If X lies in the valid range of the histogram then the function
  953.      returns zero to indicate success.  If X is less than the lower
  954.      limit of the histogram then the function returns `GSL_EDOM', and
  955.      none of bins are modified.  Similarly, if the value of X is greater
  956.      than or equal to the upper limit of the histogram then the function
  957.      returns `GSL_EDOM', and none of the bins are modified.  The error
  958.      handler is not called, however, since it is often necessary to
  959.      compute histogram for a small range of a larger dataset, ignoring
  960.      the values outside the range of interest.
  961.  
  962.  - Function: int gsl_histogram_accumulate (gsl_histogram * H, double X,
  963.           double WEIGHT)
  964.      This function is similar to `gsl_histogram_increment' but increases
  965.      the value of the appropriate bin in the histogram H by the
  966.      floating-point number WEIGHT.
  967.  
  968.  - Function: double gsl_histogram_get (const gsl_histogram * H, size_t
  969.           I)
  970.      This function returns the contents of the Ith bin of the histogram
  971.      H.  If I lies outside the valid range of indices for the histogram
  972.      then the error handler is called with an error code of `GSL_EDOM'
  973.      and the function returns 0.
  974.  
  975.  - Function: int gsl_histogram_get_range (const gsl_histogram * H,
  976.           size_t I, double * LOWER, double * UPPER)
  977.      This function finds the upper and lower range limits of the Ith
  978.      bin of the histogram H.  If the index I is valid then the
  979.      corresponding range limits are stored in LOWER and UPPER.  The
  980.      lower limit is inclusive (i.e. events with this coordinate are
  981.      included in the bin) and the upper limit is exclusive (i.e. events
  982.      with the coordinate of the upper limit are excluded and fall in the
  983.      neighboring higher bin, if it exists).  The function returns 0 to
  984.      indicate success.  If I lies outside the valid range of indices for
  985.      the histogram then the error handler is called and the function
  986.      returns an error code of `GSL_EDOM'.
  987.  
  988.  - Function: double gsl_histogram_max (const gsl_histogram * H)
  989.  - Function: double gsl_histogram_min (const gsl_histogram * H)
  990.  - Function: size_t gsl_histogram_bins (const gsl_histogram * H)
  991.      These functions return the maximum upper and minimum lower range
  992.      limits and the number of bins of the histogram H.  They provide a
  993.      way of determining these values without accessing the
  994.      `gsl_histogram' struct directly.
  995.  
  996.  - Function: void gsl_histogram_reset (gsl_histogram * H)
  997.      This function resets all the bins in the histogram H to zero.
  998.  
  999. 
  1000. File: gsl-ref.info,  Node: Searching histogram ranges,  Next: Histogram Statistics,  Prev: Updating and accessing histogram elements,  Up: Histograms
  1001.  
  1002. Searching histogram ranges
  1003. ==========================
  1004.  
  1005.    The following functions are used by the access and update routines to
  1006. locate the bin which corresponds to a given x coordinate.
  1007.  
  1008.  - Function: int gsl_histogram_find_impl (size_t N, const double
  1009.           RANGE[], double X, size_t * I)
  1010.      This function finds and sets the index I to the offset in the
  1011.      array RANGE of size N which bounds the value of X, such that
  1012.      range[i] \le  x < range[i+1].  The binary search function
  1013.      `bsearch' from the system C-library is used to locate the
  1014.      appropriate range.  If a suitable value of I is found then the
  1015.      function returns 0 to indicate success.  If X is less than the
  1016.      lower limit the function returns -1, and if X is greater than or
  1017.      equal to the upper limit it returns +1.  The error handler is not
  1018.      called.
  1019.  
  1020.  - Function: int gsl_histogram_find (const gsl_histogram * H, double X,
  1021.           size_t * I)
  1022.      This function uses `gsl_histogram_find_impl' to set the index I to
  1023.      the bin number which covers the coordinate X in the histogram H.
  1024.      If X is found then the function sets the index I and returns zero
  1025.      to indicate success.  If X lies outside the valid range of the
  1026.      histogram then the function returns `GSL_EDOM' and the error
  1027.      handler is invoked.
  1028.  
  1029. 
  1030. File: gsl-ref.info,  Node: Histogram Statistics,  Next: Histogram Operations,  Prev: Searching histogram ranges,  Up: Histograms
  1031.  
  1032. Histogram Statistics
  1033. ====================
  1034.  
  1035.  - Function: double gsl_histogram_max_val (const gsl_histogram * H)
  1036.      This function returns the maximum value contained in the histogram
  1037.      bins.
  1038.  
  1039.  - Function: size_t gsl_histogram_max_bin (const gsl_histogram * H)
  1040.      This function returns the index of the bin containing the maximum
  1041.      value. In the case where several bins contain the same maximum
  1042.      value the smallest index is returned.
  1043.  
  1044.  - Function: double gsl_histogram_min_val (const gsl_histogram * H)
  1045.      This function returns the minimum value contained in the histogram
  1046.      bins.
  1047.  
  1048.  - Function: size_t gsl_histogram_min_bin (const gsl_histogram * H)
  1049.      This function returns the index of the bin containing the minimum
  1050.      value. In the case where several bins contain the same maximum
  1051.      value the smallest index is returned.
  1052.  
  1053.  - Function: double gsl_histogram_mean (const gsl_histogram * H)
  1054.      This function returns the mean of the histogrammed variable, where
  1055.      the histogram is regarded as a probability distribution. Negative
  1056.      bin values are ignored for the purposes of this calculation.
  1057.  
  1058.  - Function: double gsl_histogram_sigma (const gsl_histogram * H)
  1059.      This function returns the standard deviation of the histogrammed
  1060.      variable, where the histogram is regarded as a probability
  1061.      distribution. Negative bin values are ignored for the purposes of
  1062.      this calculation.
  1063.  
  1064. 
  1065. File: gsl-ref.info,  Node: Histogram Operations,  Next: Reading and writing histograms,  Prev: Histogram Statistics,  Up: Histograms
  1066.  
  1067. Histogram Operations
  1068. ====================
  1069.  
  1070.  - Function: int gsl_histogram_equal_bins_p (const gsl_histogram *H1,
  1071.           const gsl_histogram *H2)
  1072.      This function returns 1 if the all of the individual bin ranges of
  1073.      the two histograms are identical, and 0 otherwise.
  1074.  
  1075.  - Function: int gsl_histogram_add (gsl_histogram *H1, const
  1076.           gsl_histogram *H2)
  1077.      This function adds the contents of the bins in histogram H2 to the
  1078.      corresponding bins of histogram H1.  i.e. h'_1(i) = h_1(i) +
  1079.      h_2(i).
  1080.  
  1081.  - Function: int gsl_histogram_sub (gsl_histogram *H1, const
  1082.           gsl_histogram *H2)
  1083.      This function subtracts the contents of the bins in histogram H2
  1084.      from the corresponding bins of histogram H1.  i.e. h'_1(i) =
  1085.      h_1(i) - h_2(i).
  1086.  
  1087.  - Function: int gsl_histogram_mul (gsl_histogram *H1, const
  1088.           gsl_histogram *H2)
  1089.      This function multiplies the contents of the bins of histogram H1
  1090.      by the contents of the corresponding bins in histogram H2.  i.e.
  1091.      h'_1(i) = h_1(i) * h_2(i).
  1092.  
  1093.  - Function: int gsl_histogram_div (gsl_histogram *H1, const
  1094.           gsl_histogram *H2)
  1095.      This function divides the contents of the bins of histogram H1 by
  1096.      the contents of the corresponding bins in histogram H2.  i.e.
  1097.      h'_1(i) = h_1(i) / h_2(i).
  1098.  
  1099.  - Function: int gsl_histogram_scale (gsl_histogram *H, double SCALE)
  1100.      This function multiplies the contents of the bins of histogram H
  1101.      by the constant SCALE.  i.e. h'_1(i) = h_1(i) scale.
  1102.  
  1103.  - Function: int gsl_histogram_shift (gsl_histogram *H, double OFFSET)
  1104.      This function shifts the contents of the bins of histogram H by
  1105.      the constant OFFSET.  i.e. h'_1(i) = h_1(i) + offset.
  1106.  
  1107. 
  1108. File: gsl-ref.info,  Node: Reading and writing histograms,  Next: Resampling from histograms,  Prev: Histogram Operations,  Up: Histograms
  1109.  
  1110. Reading and writing histograms
  1111. ==============================
  1112.  
  1113.    The library provides functions for reading and writing histograms to
  1114. a file as binary data or formatted text.
  1115.  
  1116.  - Function: int gsl_histogram_fwrite (FILE * STREAM, const
  1117.           gsl_histogram * H)
  1118.      This function writes the ranges and bins of the histogram H to the
  1119.      stream STREAM in binary format.  The return value is 0 for success
  1120.      and `GSL_EFAILED' if there was a problem writing to the file.
  1121.      Since the data is written in the native binary format it may not
  1122.      be portable between different architectures.
  1123.  
  1124.  - Function: int gsl_histogram_fread (FILE * STREAM, gsl_histogram * H)
  1125.      This function reads into the histogram H from the open stream
  1126.      STREAM in binary format.  The histogram H must be preallocated
  1127.      with the correct size since the function uses the number of bins
  1128.      in H to determine how many bytes to read.  The return value is 0
  1129.      for success and `GSL_EFAILED' if there was a problem reading from
  1130.      the file.  The data is assumed to have been written in the native
  1131.      binary format on the same architecture.
  1132.  
  1133.  - Function: int gsl_histogram_fprintf (FILE * STREAM, const
  1134.           gsl_histogram * H, const char * RANGE_FORMAT, const char *
  1135.           BIN_FORMAT)
  1136.      This function writes the ranges and bins of the histogram H
  1137.      line-by-line to the stream STREAM using the format specifiers
  1138.      RANGE_FORMAT and BIN_FORMAT.  These should be one of the `%g',
  1139.      `%e' or `%f' formats for floating point numbers.  The function
  1140.      returns 0 for success and `GSL_EFAILED' if there was a problem
  1141.      writing to the file.  The histogram output is formatted in three
  1142.      columns, and the columns are separated by spaces, like this,
  1143.  
  1144.           range[0] range[1] bin[0]
  1145.           range[1] range[2] bin[1]
  1146.           range[2] range[3] bin[2]
  1147.           ....
  1148.           range[n-1] range[n] bin[n-1]
  1149.  
  1150.      The values of the ranges are formatted using RANGE_FORMAT and the
  1151.      value of the bins are formatted using BIN_FORMAT.  Each line
  1152.      contains the lower and upper limit of the range of the bins and the
  1153.      value of the bin itself.  Since the upper limit of one bin is the
  1154.      lower limit of the next there is duplication of these values
  1155.      between lines but this allows the histogram to be manipulated with
  1156.      line-oriented tools.
  1157.  
  1158.  - Function: int gsl_histogram_fscanf (FILE * STREAM, gsl_histogram * H)
  1159.      This function reads formatted data from the stream STREAM into the
  1160.      histogram H.  The data is assumed to be in the three-column format
  1161.      used by `gsl_histogram_fprintf'.  The histogram H must be
  1162.      preallocated with the correct length since the function uses the
  1163.      size of H to determine how many numbers to read.  The function
  1164.      returns 0 for success and `GSL_EFAILED' if there was a problem
  1165.      reading from the file.
  1166.  
  1167. 
  1168. File: gsl-ref.info,  Node: Resampling from histograms,  Next: The histogram probability distribution struct,  Prev: Reading and writing histograms,  Up: Histograms
  1169.  
  1170. Resampling from histograms
  1171. ==========================
  1172.  
  1173.    A histogram made by counting events can be regarded as a measurement
  1174. of a probability distribution.  Allowing for statistical error, the
  1175. height of each bin represents the probability of an event where the
  1176. value of x falls in the range of that bin.  The probability distribution
  1177. function has the one-dimensional form p(x)dx where,
  1178.  
  1179.      p(x) = n_i/ (N w_i)
  1180.  
  1181. In this equation n_i is the number of events in the bin which contains
  1182. x, w_i is the width of the bin and N is the total number of events.
  1183. The distribution of events within each bin is assumed to be uniform.
  1184.  
  1185.